#include<iostream>
#include<algorithm>
#include<vector>


using namespace std;

class Solution {
public:
    int majorityElement(vector<int>& nums)
    {
        auto it = nums.begin();
        sort(nums.begin(), nums.end());
        int _count = 1;
        while ((it + 1) != nums.end())
        {
            if (*it == *(it + 1))
            {
                _count++;
            }
            else
            {
                _count = 1;
            }
            if (_count > nums.size() / 2)
            {
                return *it;
            }
            it++;
        }
        return *it;
    }
};




class Solution {
public:
    int majorityElement(vector<int>& nums)
    {
        sort(nums.begin(), nums.end());
        return nums[nums.size() / 2];
    }
};